<?php

namespace app\admin\controller;
use think\Db;

class Login extends \think\Controller{
	
	public function index(){
		return $this->fetch();
	}

	
	/*
	检测登录信息
	 */
	public function checkInfo(){
		if (request()->method() == 'POST') {
			$data = request()->param();
			$username = $data['username'];
			$password = $data['password'];
			$code     = $data['code'];
			$user_info = Db::table('tp_admin')->where('name',$username)->where('password',md5($password))->field('id,name')->find();
			if (empty($user_info)) {
				return ['code'=>1,'msg'=>'用户名或密码错误'];
			}
			if(!captcha_check($code)){
			 	// return ['code'=>1,'msg'=>'验证码错误'];
			};
			session('user_info',$user_info);
			session('ip',request()->ip());
			return ['code'=>0,'msg'=>'登录成功'];
		}
	}


	/**
    * 退出
    */
    public function logout(){
        $loginData = session('user_info');
        session('user_info', null);
        $this->redirect('Login/index');
    }
}